package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.VehicleMapper;
import com.ruoyi.system.domain.Vehicle;
import com.ruoyi.system.service.IVehicleService;
import com.ruoyi.common.core.text.Convert;

/**
 * 小区车辆信息Service业务层处理
 * 
 * @author 祖新宇
 * @date 2024-12-18
 */
@Service
public class VehicleServiceImpl extends ServiceImpl<VehicleMapper,Vehicle> implements IVehicleService

{
    @Autowired
    private VehicleMapper vehicleMapper;

    /**
     * 查询小区车辆信息
     * 
     * @param id 小区车辆信息主键
     * @return 小区车辆信息
     */
    @Override
    public Vehicle selectVehicleById(Long id)
    {
        return vehicleMapper.selectVehicleById(id);
    }

    /**
     * 查询小区车辆信息列表
     * 
     * @param vehicle 小区车辆信息
     * @return 小区车辆信息
     */
    @Override
    public List<Vehicle> selectVehicleList(Vehicle vehicle)
    {
        return vehicleMapper.selectVehicleList(vehicle);
    }

    /**
     * 新增小区车辆信息
     * 
     * @param vehicle 小区车辆信息
     * @return 结果
     */
    @Override
    public int insertVehicle(Vehicle vehicle)
    {
        vehicle.setCreateTime(DateUtils.getNowDate());
        return vehicleMapper.insertVehicle(vehicle);
    }

    /**
     * 修改小区车辆信息
     * 
     * @param vehicle 小区车辆信息
     * @return 结果
     */
    @Override
    public int updateVehicle(Vehicle vehicle)
    {
        vehicle.setUpdateTime(DateUtils.getNowDate());
        return vehicleMapper.updateVehicle(vehicle);
    }

    /**
     * 批量删除小区车辆信息
     * 
     * @param ids 需要删除的小区车辆信息主键
     * @return 结果
     */
    @Override
    public int deleteVehicleByIds(String ids)
    {
        return vehicleMapper.deleteVehicleByIds(Convert.toStrArray(ids));
    }

    /**
     * 批量软删除小区车辆信息
     *
     * @param ids 需要软删除的小区车辆信息主键
     * @return 结果
     */
    @Override
    public int softDeleteVehicleByIds(String ids)
    {
        String[] strArray = Convert.toStrArray(ids);
        int count = 0;
        for (String s : strArray) {
            Vehicle vehicle = vehicleMapper.selectVehicleById(Long.valueOf(s));
            vehicle.setIsDelete(1);
            int i = vehicleMapper.updateVehicle(vehicle);
            count = count + i;
        }
        return count;
    }

    /**
     * 删除小区车辆信息信息
     * 
     * @param id 小区车辆信息主键
     * @return 结果
     */
    @Override
    public int deleteVehicleById(Long id)
    {
        return vehicleMapper.deleteVehicleById(id);
    }
}
